package com.demo.controller.media;

import com.demo.common.kit.SensitiveWordsKit;
import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

/**
 * @Auther: 10091
 * @Date: 2018-07-14 10:14
 * @Description:
 */
public class MediaValidator extends Validator {

    protected void validate(Controller c) {
        setShortCircuit(true);

        checkSensitiveWords(c.getPara("media.mediaName"), "媒体号 title 包含敏感词");
        //checkSensitiveWords(c.getPara("media.content"), "反馈内容 content 名包含敏感词");

        validateString("media.mediaName", 3, 20, "msg", "标题长度要求在3到20个字符");

       /* validateInteger("feedback.projectId", "msg", "请选择关联项目");
        if ( ! MyProjectService.me.isProjectIdExists(c.getParaToInt("feedback.projectId")) ) {
            addError("msg", "关联项目不存在，请联系管理员");
        }*/

        validateString("media.mediaAbstract", 0, 65536, "msg", "内容长度在0~65536个字符");
    }

    private void checkSensitiveWords(String value, String msg) {
        if (SensitiveWordsKit.checkSensitiveWord(value) != null) {
            addError("msg", msg);
        }
    }

    protected void handleError(Controller c) {
        c.renderJson();
    }
}
